/*===== code build by mstore0.1.3 =====*/

/*===== mstoreDev/common#storeHeader:0 =====*/

$$(function($it){

    $it.listen('click', {
        createProject: function(){
            $$.action.openCreateProject();
        },
        openDir: function(){
            $$.action.openDir($(this).attr('path'));
        },
        viewDocs: function(){
            open('/@doc@/');
        },
        end: null
    });
    
});

/*===== mstoreDev/mytasks#pageConfig:0 =====*/

$$(function($it){
    
    $it.click({
        doEditor: function(){
            location.href = $(this).attr('path') + '.html?$edit=mstore';
        },
        removeTopStoreTask: function(e){
            e.stopPropagation();
            var $storeTask = $(this).parents('.topStoreTask');
            $it.ajax.editStoreTaskTop(false, $storeTask.attr('path'), function(){
                location.reload();
            });
        },
        addTopStoreTask: function(e){
            e.stopPropagation();
            var $storeTask = $(this).parents('.storeTask');
            $it.ajax.editStoreTaskTop(true, $storeTask.attr('path'), function(){
                location.reload();
            });
        },
        openProjectDir: function(e){
            e.stopPropagation();
            $$.action.openDir('mstore/'+ $(this).parents('.myTasks').attr('projectId'));
        },
        buildProject: function(e){
            e.stopPropagation();
            open($(this).parents('.myTasks').attr('projectId') + '.build');
        },
        openEditStoreTaskDesc: function(e){
            e.stopPropagation();
            var $storeTask = $(this).parents('li');
            var $taskDescText = $storeTask.find('.taskDescText');
            //var taskDesc = prompt("请输入备注", $taskDescText.text()); 
            var taskDesc;
            layer.prompt({
                formType: 2,
                title: '请设置备注',
                value: $taskDescText.text(),
                area: ['600px', '80px'], //自定义文本域宽高
            }, function(value, index, elem){
                taskDesc = value; //得到value
                layer.close(index);
                $it.ajax.editStoreTaskDesc(taskDesc, $storeTask.attr('path'), function(){
                    $taskDescText.text(taskDesc);
                });
            });
        },
        removeStoreTask: function(e){
            e.stopPropagation();
            var $storeTask = $(this).parents('.storeTask');
            $it.ajax.removeStoreTask($storeTask.attr('path'), function(){
                location.reload();
            });
        }
    });
    
    $it.ajax({
        editStoreTaskDesc: function(taskDesc, taskPath, callback){
            $util.ajax(function(resp){
                if(resp.err){
                    layer.alert(resp.err);
                }else{
                    callback();
                }
            }, {
                cmd: 'task_edit_desc',
                path: taskPath,
                desc: taskDesc
           });
        },
        editStoreTaskTop: function(isTop, taskPath, callback){
            $util.ajax(function(resp){
                if(resp.err){
                    layer.alert(resp.err);
                }else{
                    callback();
                }
            }, {
                cmd: 'task_edit_top',
                path: taskPath,
                isTop: isTop ? '1' : '0'
           });
        },
        removeStoreTask: function(taskPath, callback){
            $util.ajax(function(resp){
                if(resp.err){
                    layer.alert(resp.err);
                }else{
                    callback();
                }
            }, {
                cmd: 'task_remove',
                path: taskPath
           });
        }
    });
});
